var $;
layui.use(['form','layer','jquery','laypage'],function() {
    var form = layui.form(),
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        $ = layui.jquery;

    $(".search_btn").click(function(){
        var querystr = $(".search_input").val();
        var send_status = $('.select-send-status').val();
        location.href = '/order/index?querystr=' + querystr+'&status='+send_status;
        layer.msg('查询中，请稍候');
    });

    $('.change-status').click(function(){
        var id = $(this).attr('data-id');
        // location.href = '/order/getstatus?id=' + id;
        var index = layui.layer.open({
            title : "修改订单状态",
            type : 2,
            content : "/order/getstatus?id="+id,
            success : function(layero, index){
                setTimeout(function(){
                    layui.layer.tips('点击此处返回权限列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500)
            }
        });
      //  改变窗口大小时，重置弹窗的高度，防止超出可视区域（如F12调出debug的操作）
        $(window).resize(function(){
            layui.layer.full(index);
        });
        layui.layer.full(index);

    });
    $('.submit-change-status').click(function(){
      var data =  $('.submit-change-status-form').serialize();
      event.preventDefault();
       $.ajax({
           url: '/order/changestatus',
           type: 'POST',
           dataType: 'json',
           timeout: 3000,
           data: data,
           success:function(ret){
               if(ret.status==1){
                   layer.msg("修改成功");
                   location.href= '/order/index';
               }else{
                   layer.msg("修改失败");
               }
           },
           error:function(){
               layer.msg("修改失败");
           }
       });
    });

    $(".look-detail").on('click',function(){
        var id = $(this).attr('data-id');
        var html = '';
        $.ajax({
            url:'/order/getorderdetail',
            type:"get",
            dataType: 'json',
            data:{id:id},
            success:function(ret){
                    if(ret.status==1){
                        var pay = '';
                        var send = '';
                        if(ret.data.pay_status==0){
                            pay = '未支付';
                        }else if(ret.data.pay_status==1){
                            pay = '已支付';
                        }else{
                            pay = '已退款';
                        }

                        if(ret.data.send_status==0){
                            send = '未发货';
                        }else if(ret.data.pay_status==1){
                            send = '已发货';
                        }else{
                            send = '已退货';
                        }


                        html = '<div class="layui-form" style="width:80%;margin-top:10px;">' +
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">用户ID</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly" value="'+ret.data.uid+'" >' +
                            '</div>' +
                            '</div>' +
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">地区</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly" value="'+ret.data.area+'">' +
                            '</div>' +
                            '</div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">地址</label>' +
                            '<div class="layui-input-block">' +
                            // "<span>"+ret.data.address+"</span>"+
                            '<textarea class="layui-input"   readonly="readonly" style="resize:none;height:auto;">'+ret.data.address+'</textarea></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">收件人</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly"  value="'+ret.data.receiver+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">收件人联系方式</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly"  value="'+ret.data.receiver_tel+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">支付状态</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly" value="'+pay+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">发货状态</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly" value="'+send+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">运单号</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"   readonly="readonly" value="'+ret.data.send_no+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">快递公司</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly" value="'+ret.data.send_company+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">订单编号</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly" value="'+ret.data.order_no+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">商品名称</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly" value="'+ret.data.goods_name+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">商品数量</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"   readonly="readonly" value="'+ret.data.num+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">积分</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly"  value="'+ret.data.scores+'"></div></div>'+
                            '<div class="layui-form-item">' +
                            '<label class="layui-form-label">优惠</label>' +
                            '<div class="layui-input-block">' +
                            '<input type="text" class="layui-input"  readonly="readonly" value="'+ret.data.coupon+'"></div></div>'+
                            '</div>';
                        layer.open({
                            title:'订单详情',
                            type: 1,
                            skin: 'layui-layer-rim', //加上边框
                            area: ['640px', '460px'], //宽高
                            content:html
                        });


                    }else{
                        layer.msg("查看失败");
                    }
            },error:function(){
                layer.msg("查看失败");
            }

        });


    });
});



